﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using testy;

namespace pytator {
	public partial class QuestionControl : UserControl {
		List<CheckBox> answers;
		public QuestionControl() {
			InitializeComponent();
			answers = new List<CheckBox>();
		}
		public void loadQuestion(CheckedQuestion q) {
			this.cleanControl();
			this.displayContent(q.Content, q.CheckedCount);
			this.displayAnswers(q);
		}
		private void cleanControl() {
			while(this.Controls.Count > 0) {
				this.Controls.RemoveAt(0);
			}
			this.answers.Clear();
		}
		private void displayContent(string c, int cc) { //wyświetlenie pytania
			this.QuestionContentLabel = new Label();
			this.QuestionContentLabel.Dock = DockStyle.Top;
			string wEnd = "";
			string oEnd = "";
			string sufix = "";
			if(cc == 1) {
				wEnd = "a";
				oEnd = "ź";
			} else if(new List<Int32>(new int[] { 2, 3, 4 }).Contains(cc%10)) {
				wEnd = "e";
				oEnd = "zi";
			} else {
				wEnd = "ych";
				oEnd = "zi";
			}
			if(cc > 0) {
				sufix = " ("+cc+" wymagan"+wEnd+" odpowied"+oEnd+")";
			}
			this.QuestionContentLabel.Text = c+sufix;
			this.QuestionContentLabel.Location = new Point(5, 0);
			this.Controls.Add(this.QuestionContentLabel);
		}
		private void displayAnswers(CheckedQuestion q) { //wyświetlenie możliwych odpowiedzi
			for(int i=0; i<q.Answers.Count; i++) {
				CheckBox c = new CheckBox();
				c.Location = new Point(5, 20*i+20);
				c.Text = q.Answers[i].Content;
				c.Checked = q.Answers[i].IsChecked;
				this.answers.Add(c);
				this.Controls.Add(c);
			}
		}
		public List<bool> getAnswers() { //pobranie odpowiedzi użytkownika
			List<bool> odps = new List<bool>();
			for(int i=0; i<this.answers.Count; i++) {
				odps.Add(this.answers[i].Checked);
			}
			return odps;
		}
	}
}
